package com.wsoft.mq.config;

import com.wsoft.mq.constant.ImConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author z001
 * @Date 2025/1/14 14:08
 */
@Configuration
public class ImConfig {


    //################################### from_user 单聊 ###################################
    /**
     * 定义交换机
     * @return
     */
    @Bean
    public DirectExchange formUserSingleExchange() {
        // 持久化，不自动删除
        return new DirectExchange(ImConstant.IM_FORM_USER_SINGLE_DIRECT_EXCHANGE, true, false);
    }

    @Bean
    public Queue formUserSingleQueue() {
        //持久化
        return new Queue(ImConstant.IM_FORM_USER_SINGLE_QUEUE, true);
    }

    @Bean
    public Binding formUserSingleBinding() {
        return BindingBuilder.bind(formUserSingleQueue())
                .to(formUserSingleExchange())
                .with(ImConstant.IM_FORM_USER_SINGLE_KEY);
    }

    //################################### from_user   群聊 ###################################
    /**
     * 定义交换机
     * @return
     */
    @Bean
    public DirectExchange formUserGroupExchange() {
        // 持久化，不自动删除
        return new DirectExchange(ImConstant.IM_FORM_USER_GROUP_DIRECT_EXCHANGE, true, false);
    }

    @Bean
    public Queue formUserGroupQueue() {
        //持久化
        return new Queue(ImConstant.IM_FORM_USER_GROUP_QUEUE, true);
    }

    @Bean
    public Binding formUserGroupBinding() {
        return BindingBuilder.bind(formUserGroupQueue())
                .to(formUserGroupExchange())
                .with(ImConstant.IM_FORM_USER_GROUP_KEY);
    }



    //################################### to_user 单聊 ###################################
    /**
     * 定义交换机
     * @return
     */
    @Bean
    public DirectExchange toUserSingleExchange() {
        // 持久化，不自动删除
        return new DirectExchange(ImConstant.IM_TO_USER_SINGLE_DIRECT_EXCHANGE, true, false);
    }

    @Bean
    public Queue toUserSingleQueue() {
        //持久化
        return new Queue(ImConstant.IM_TO_USER_SINGLE_QUEUE, true);
    }

    @Bean
    public Binding toUserSingleBinding() {
        return BindingBuilder.bind(toUserSingleQueue())
                .to(toUserSingleExchange())
                .with(ImConstant.IM_TO_USER_SINGLE_KEY);
    }

    //################################### to_user 群聊 ###################################
    /**
     * 定义交换机
     * @return
     */
    @Bean
    public DirectExchange toUserGroupExchange() {
        // 持久化，不自动删除
        return new DirectExchange(ImConstant.IM_TO_USER_GROUP_DIRECT_EXCHANGE, true, false);
    }

    @Bean
    public Queue toUserGroupQueue() {
        //持久化
        return new Queue(ImConstant.IM_TO_USER_GROUP_QUEUE, true);
    }

    @Bean
    public Binding toUserGroupBinding() {
        return BindingBuilder.bind(toUserGroupQueue())
                .to(toUserGroupExchange())
                .with(ImConstant.IM_TO_USER_GROUP_KEY);
    }

}
